package com.db.concurrency;

public class SynchronizedCacheImpl<K, V> implements Cache<K, V> {

  private K key;
  private V value;
  
  @Override
  public synchronized V get(K key) {
    if (key == null) {
      throw new NullPointerException();
    }
    return key.equals(this.key) ? value : null;
  }

  @Override
  public synchronized void put(K key, V value) {
    if (key == null) {
      throw new NullPointerException();
    }
    this.key = key;
    this.value = value;
  }

}
